package subject_set.top101;

import java.util.HashSet;
import java.util.Set;

/**
 * @author haomin
 * @date 2023/01/01 23:10
 **/
public class BM92 {
    public class Solution {
        /**
         *
         * @param arr int整型一维数组 the array
         * @return int整型
         */
        public int maxLength (int[] arr) {
            // write code here
            int max = 0, i = 0, j = 0;
            Set<Integer> s = new HashSet<>();
            for(; j < arr.length;) {
                if(s.add(arr[j])) j++;
                else {s.remove(arr[i]); i++;}
                max = Math.max(max, j-i);
            }
            return max;
        }
    }
}